You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[#707] Issue the remember-me token only after the OTP, and renew the session ID on every sign-in - #713
With two-factor authentication on, SessionAuthAdapter issues the remember-me token and cookie only after the OTP is verified, and every sign-in gets a new session ID.
signin() with two-factor on issues no remember token. It records in the session of the browser that signed in that "remember me" was asked for; a sign-in without it, and signout(), remove that record.
verifyOtp() issues the remember token and cookie when the record matches the verified user, removes the record, and regenerates the session ID before it signs the user in.
A sign-in through the remember cookie in user() also regenerates the session ID.
With two-factor off, sign-in and remember-me work as before. The JWT adapter is not changed.
Why
signin() issued the remember token before the OTP step, and checkRememberToken() refused the cookie only while an OTP was pending. When the owner then completed an OTP sign-in in another browser, the pending OTP was cleared and the cookie of the unverified sign-in signed in without its OTP. A failure while storing the OTP left a working remember token at once.
verifyOtp() and the remember-cookie sign-in kept the session ID the browser had before, while signin() without two-factor regenerates it, so a session ID planted before such a sign-in stayed valid for the signed-in user.
a remember sign-in with two-factor on sets no cookie before the OTP (a cookie was set);
the cookie of a sign-in whose OTP was never entered does not sign in after the owner verifies an OTP elsewhere (it signed in), and no remember token is stored;
when storing the OTP fails, no remember token is stored (one was);
a later sign-in without "remember me", also one whose OTP mail fails, and signout() before the OTP leave no cookie (the earlier request was applied);
when storing the remember token fails in verifyOtp(), no remember request is left in the session;
verifyOtp() and a remember-cookie sign-in change the session ID (it stayed the same), keep the session data, and a later user() keeps the new ID.
Tests that pass before and after: remember-me after a verified OTP and after resendOtp(), no cookie without "remember me", remember-me with two-factor off, and the existing auth tests.
Before and after, on 12 sign-in scenarios run against the old and the new adapter: every scenario that worked before behaves the same; the remember cookie of an unverified sign-in, after a failed OTP store, after a declined later sign-in and after an abandoned sign-in no longer signs in; the session ID changes after the OTP and on a remember-cookie sign-in.
Remember tokens issued before the upgrade are not revoked; the changelog tells applications how to clear them. The starter project needs no change: its web module signs in, verifies and resends in the same browser, and nothing in it reads the session ID or the remember cookie.
Summary by CodeRabbit
Security
When two-factor authentication is enabled, “Remember me” is applied only after successful OTP verification. Sign-ins without two-factor authentication are unchanged.
Sessions are refreshed after OTP verification and when signing in with a remember-me cookie, while preserving session data.
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Restore cart after both session-ID tests.
Both tests leave cart=kept in shared session storage. signout() does not remove it, and inherited teardown clears configuration and application context, not session contents. Native session storage references $_SESSION. (raw.githubusercontent.com)
Save the previous value and restore it in finally. If the key was absent, delete it instead. This prevents these fixtures from affecting later tests.
Based on learnings, tests that mutate shared global state must restore it even when an assertion throws.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #707
What
With two-factor authentication on,
SessionAuthAdapterissues the remember-me token and cookie only after the OTP is verified, and every sign-in gets a new session ID.signin()with two-factor on issues no remember token. It records in the session of the browser that signed in that "remember me" was asked for; a sign-in without it, andsignout(), remove that record.verifyOtp()issues the remember token and cookie when the record matches the verified user, removes the record, and regenerates the session ID before it signs the user in.user()also regenerates the session ID.Why
signin()issued the remember token before the OTP step, andcheckRememberToken()refused the cookie only while an OTP was pending. When the owner then completed an OTP sign-in in another browser, the pending OTP was cleared and the cookie of the unverified sign-in signed in without its OTP. A failure while storing the OTP left a working remember token at once.verifyOtp()and the remember-cookie sign-in kept the session ID the browser had before, whilesignin()without two-factor regenerates it, so a session ID planted before such a sign-in stayed valid for the signed-in user.Changed paths
src/Auth/Adapters/SessionAuthAdapter.phptests/Unit/Auth/Adapters/SessionAuthAdapterTest.phpCHANGELOG.mdTesting
New tests that fail without the change:
signout()before the OTP leave no cookie (the earlier request was applied);verifyOtp(), no remember request is left in the session;verifyOtp()and a remember-cookie sign-in change the session ID (it stayed the same), keep the session data, and a lateruser()keeps the new ID.Tests that pass before and after: remember-me after a verified OTP and after
resendOtp(), no cookie without "remember me", remember-me with two-factor off, and the existing auth tests.Before and after, on 12 sign-in scenarios run against the old and the new adapter: every scenario that worked before behaves the same; the remember cookie of an unverified sign-in, after a failed OTP store, after a declined later sign-in and after an abandoned sign-in no longer signs in; the session ID changes after the OTP and on a remember-cookie sign-in.
Remember tokens issued before the upgrade are not revoked; the changelog tells applications how to clear them. The starter project needs no change: its web module signs in, verifies and resends in the same browser, and nothing in it reads the session ID or the remember cookie.
Summary by CodeRabbit